
import FSC from '@bwt/fscjs'
let fsc
import eventBus from '@/plugins/eventBus';
import { mountOverview } from '@/ssp/home'

export function mountSoonSpace(node, sceneId, appId, publicKey) {

  initScene(node, sceneId, appId, publicKey)
}

/**
 * 初始化场景
 */
function initScene(el, sceneId, appId, publicKey) {

  fsc = new FSC({
    pravite: false,
    appId: appId,
    baseUrl: 'https://bimdta-dev.bwton-console.cn/digitaltwins-foundation-open',
    el: el,
    sceneId: sceneId,
    publicKey: publicKey,
    dracoPath: './draco/',
    initSceneOptions: {
      hoverEnabled: false,
      scaleFixedEnabled: false,
      background: {
        color: 0x0f3d43
      }
    },
    events: {
      modelClick: modelClick,
      poiClick: poiClick
    },
    ready: () => {
      sceneReady()
    },
    errorCallback: (e) => {
      sceneError(e)
    }
  })

}

function sceneReady() {
  console.log('场景加载完成', fsc);
  window.fsc = fsc;
  window.ssp = fsc.ssp;
  eventBus.emit('custom-event', { message: 'Hello from ComponentA' })

  // mountOverview(fsc)
}
/**
 * 模型加载失败回调，可根据需要在此处弹出错误信息提示，目前未弹
 */
function sceneError(e) {
  console.log('场景加载失败', e)
}

/**
* 模型点击事件
*/
function modelClick(value) {
  const { target } = value
  console.log('modelClick====', target)
}

/**
 * POI点击事件
 */
function poiClick(value) {
  const { target } = value
  console.log('poiClick====', target)
}

/**
 * 
 * @returns 孪生体
 */

//根据查询条件获取孪生体列表
export async function queryTwins() {
  const twins = await fsc.queryTwins()
  return twins
}

//显示孪生体POI
export function showTwinsPoi(twinsId) {
  fsc.showTwinsPoi(twinsId)
}

//隐藏孪生体Poi
export function hideTwinsPoi(twinsId) {
  fsc.hideTwinsPoi(twinsId)
}

//显示孪生体面板
export function showTwinsPanel(twinsId) {
  fsc.showTwinsPanel(twinsId)
}

//隐藏孪生体面板
export function hideTwinsPanel(twinsId) {
  fsc.hideTwinsPanel(twinsId)
}

/**
 * 
 * @returns 孪生体实例
 */
//查询孪生体实例列表
export async function queryInstance(params) {
  try {

    const param = {
      page_no: 1,
      page_size: 999,
      ...params
    }
    const list = await fsc.queryInstance(param)
    console.log('queryInstance===', list)
    return list
  } catch (error) {
    console.log('error===',error)
  }

}

//查询孪生体实例详情
export async function queryInstanceInfo(ids) {
  const data = await fsc.queryInstanceInfo(ids)
  return data
}

//显示孪生体实例POI
export function showInstancePoi(twinsInstanceId) {
  fsc.showInstancePoi(twinsInstanceId)
}

//隐藏孪生体实例POI
export function hideInstancePoi(twinsInstanceId) {
  fsc.hideInstancePoi(twinsInstanceId)
}

//显示孪生体实例面板
export function showInstancePanel(twinsInstanceId) {
  fsc.showInstancePanel(twinsInstanceId)
}

//隐藏孪生体实例面板
export function hideInstancePanel(twinsInstanceId) {
  fsc.hideInstancePanel(twinsInstanceId)
}

//飞向孪生体实例
export function flyToInstance(twinsInstanceId) {
  fsc.flyToInstance(twinsInstanceId)
}

/**
 * 
 * @returns 视角
 */
//查询视角列表
export async function queryViewList(params) {
  const data = await fsc.queryViewList(params)
  return data
}

//飞向场景视角
export function flyToScene(viewId) {
  fsc.flyToScene(viewId)
}

/**
 * 
 * @returns 操作集
 */
//根据查询条件获取操作集列表
export async function queryOperators(params) {
  const data = await fsc.queryOperators(params)
  return data
}

//
export async function createOperators(operatorsId) {
  const data = await fsc.createOperators(operatorsId)
  return data
}
